/**
 * 
 */
package storyteller;

import java.lang.reflect.Method;
import com.flagstone.transform.FSColor;
import com.flagstone.transform.FSColorTable;


/**
 * @author Alex
 *
 */
public class ColorTranslator
{
  public enum Suit { }
  
  /**
   * Translates a string name to a FSColor object. Uses FSColorTable, which
   * supports all the colors defined in the Netscape color table (over 130) Uses
   * reflection to call the corresponding method's name. 
   * @param colorName English name of the color (white, black, grey, etc)
   * @return a FSColor object that is named as the colorName parameter. If the name is 
   * not found in FSColorTable, default is returned. If default is invalid, white is returned.
   */
  public static FSColor getColor(String colorName, String defaultColor)
  {
    try
    {
      // Load the class and look for the method
      Class<?> clazz = FSColorTable.class;
      Method m = clazz.getMethod(colorName.toLowerCase(), new Class[0]);
      
      // Invoque the method that corresponds to the color name
      FSColor co = (FSColor) m.invoke(null, new Object[0]);
      
      return co;      
      
    } catch (Exception e)
    {
      // Most likely method name not found (colour not defined). Return default.
      //System.err.println("Ignoring color parameter '" + colorName + "'");
      return getColor(defaultColor, "white");
    }
  }
}
